package com.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.AdminDao;

/**
 * Servlet implementation class ChangeServet
 */
@WebServlet("/ChangeServet")
public class ChangeServet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ChangeServet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");//防止出现中文乱码
		
		// 获取注册信息
		String username =request.getParameter("u");
		String password =request.getParameter("p");
		String newpassword =request.getParameter("newp");
		
		boolean a = AdminDao.login(username,password);
//		a=true注册成功 a=false注册失败
		if(a==true){
				boolean b = AdminDao.change(username,newpassword);
				if(b==true){
					request.getSession().setAttribute("A1","修改成功");
					response.sendRedirect("/aaa/change.jsp");
					}else {
					request.getSession().setAttribute("A1","修改失败");
					response.sendRedirect("/aaa/change.jsp");
					}
			}else {
			request.getSession().setAttribute("A1","当前密码错误");
			response.sendRedirect("/aaa/change.jsp");
			}
		
		
		
	}

}
